// home 小仓库
import { reqCategoryList, reqGetBannerList, reqFloorList } from '@/api'

const actions = {
  // 通过Api 里面的接口函数调用,向服务器发请求,获取服务器数据
  async categoryList({ commit }) {
    const result = await reqCategoryList()
    if (result.code == 200) {
      commit('CATEGROYLIST', result.data)
    }
  },
  // 获取首页轮播图的数据
  async getBannerList({ commit }) {
    let result = await reqGetBannerList()
    if (result.code == 200) {
      commit('GETBANNERLIST', result.data)
    }
  },
  async getFloorList({ commit }) {
    let result = await reqFloorList()
    if (result.code == 200) {
      commit('REQFLOORLIST', result.data)
    }
  }
}
const mutations = {
  CATEGROYLIST(state, categoryList) {
    state.categoryList = categoryList
  },
  GETBANNERLIST(state, bannerList) {
    state.bannerList = bannerList
  },
  REQFLOORLIST(state, floorList) {
    state.floorList = floorList
  }
}
const state = {
  // state 中的数据默认初始值别瞎写  应该看看服务器返回的数据
  categoryList: [],
  // 轮播图的数据
  bannerList: [],
  floorList: []
}
const getters = {}

export default {
  state,
  actions,
  mutations,
  getters
}
